import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
} from "vue-router";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "index", //首页
      component: () => import("@/views/Index/index.vue"),
      meta: {
        title: "深圳环球行_旅行社_欧洲旅游_出环球行游_公司旅游-环球行官方网站",
      },
    },
    {
      path: "/index",
      name: "index2", //首页
      component: () => import("@/views/Index/index.vue"),
      meta: {
        title: "深圳环球行_旅行社_欧洲旅游_出环球行游_公司旅游-环球行官方网站",
      },
    },
    {
      path: "/hqx/ChatExtraction",
      name: "ChatExtraction", // 潇洒出境
      component: () => import("@/views/myTools/parsing.vue"),
      meta: {
        title: "飞书聊天解析",
      },
    },
    // {
    //   path: "/temp",
    //   name: "temp", //临时测试页
    //   component: () => import("@/views/Index/temp.vue"),
    // },
    {
      path: "/outbound",
      name: "outbound", // 潇洒出境
      component: () => import("@/views/Outbound/outbound.vue"),
      meta: {
        title:
          "出境旅游_最新出境游报价_最新出境游线路_出环球行游_国外旅游_境外旅游-深圳环球行",
      },
    },
    {
      path: "/domestic",
      name: "domestic", // 畅玩国内
      component: () => import("@/views/Domestic/domestic.vue"),
      meta: {
        title:
          "当季特卖旅游路线|环球行旅行社|中国环球行深圳公司|深圳环球行官方网站",
      },
    },
    {
      path: "/periphery",
      name: "periphery", // 玩转广东 周边游
      component: () => import("@/views/Periphery/periphery.vue"),
      meta: {
        title: "周边旅游_广东旅游_省内旅游_深圳环球行官方网站",
      },
    },
    {
      path: "/islands",
      name: "islands", // 邂逅海岛
      component: () => import("@/views/Islands/islands.vue"),
      meta: {
        title: "海岛旅游_巴厘岛_普吉岛_沙巴岛-深圳环球行",
      },
    },
    // 主题游和主题游列表

    {
      path: "/theme/list/:theme/:des",
      name: "themeLists", // 主题游指定主题
      component: () => import("@/views/ThemeTour/lists.vue"),
      meta: {
        title: "",
      },
    },
    {
      path: "/theme/list/:theme",
      name: "themeLists2", // 主题游指定主题
      component: () => import("@/views/ThemeTour/lists.vue"),
      meta: {
        title: "",
      },
    },
    {
      path: "/theme/:id",
      name: "theme2", // 主题游展示列表
      component: () => import("@/views/ThemeTour/theme.vue"),
      meta: {
        title:
          "婚摄旅游,美食旅游,蜜月游,海岛,高尔夫旅游,游学,漂流,自驾游 - 深圳环球行主题游指南",
      },
    },
    {
      path: "/theme",
      name: "theme", // 主题游
      component: () => import("@/views/ThemeTour/theme.vue"),
      meta: {
        title:
          "婚摄旅游,美食旅游,蜜月游,海岛,高尔夫旅游,游学,漂流,自驾游 - 深圳环球行主题游指南",
      },
    },
    {
      path: "/company",
      name: "company", // 包团定制
      component: () => import("@/views/Company/company.vue"),
      meta: {
        title: "公司包团_公司旅游_包团旅游_团队旅游-中国环球行官方网站",
      },
    },
    {
      path: "/company/list/:area",
      name: "companyList", // 包团定制列表页
      component: () => import("@/views/Company/companyList.vue"),
      meta: {
        title: "公司包团_公司旅游_包团旅游_团队旅游-中国环球行官方网站",
      },
    },
    /* 团建模块开始 */
    {
      path: "/group",
      name: "group", // 狼性团建
      component: () => import("@/views/Group/group.vue"),
      meta: {
        title: "狼性团建_团建旅游_公司团建_企业团建-中国环球行官方网站",
      },
    },
    {
      path: "/group/programme",
      name: "programme", // 团建方案
      component: () => import("@/views/Group/programme.vue"),
      meta: {
        title: "团建方案_狼性团建-深圳环球行",
      },
    },
    {
      path: "/group/programme/:id",
      name: "programmeDetail", // 方案详情
      component: () => import("@/views/Group/programmeDetail.vue"),
      meta: {
        title: "",
      },
    },
    {
      path: "/group/theme",
      name: "groupTheme", // 团建主题
      component: () => import("@/views/Group/theme.vue"),
      meta: {
        title: "团建主题课程_狼性团建-深圳环球行",
      },
    },
    {
      path: "/group/theme/:id",
      name: "themeDetail", // 主题详情
      component: () => import("@/views/Group/themeDetail.vue"),
      meta: {
        title: "",
      },
    },
    {
      path: "/group/project",
      name: "project", // 团建项目
      component: () => import("@/views/Group/project.vue"),
      meta: {
        title: "经典团建项目_狼性团建-深圳环球行",
      },
    },
    {
      path: "/group/project/:id",
      name: "projectDetail", // 项目详情
      component: () => import("@/views/Group/projectDetail.vue"),
      meta: {
        title: "",
      },
    },
    {
      path: "/group/address",
      name: "address", // 团建基地
      component: () => import("@/views/Group/address.vue"),
      meta: {
        title: "团建基地_狼性团建-深圳环球行",
      },
    },
    {
      path: "/group/address/:id",
      name: "addressDetail", // 基地详情
      component: () => import("@/views/Group/addressDetail.vue"),
      meta: {
        title: "",
      },
    },
    {
      path: "/line/:area",
      name: "line", // 目的地 国内旅游列表
      component: () => import("@/views/Line/line.vue"),
      meta: {
        title: "旅游线路报价,中国环球行官网",
      },
    },
    // {
    //   path: "/linenew/:area",
    //   name: "linenew", // 目的地 国内旅游列表
    //   component: () => import("@/views/Line/lineNew.vue"),
    //   meta: {
    //     title: "旅游线路报价,中国环球行官网",
    //   },
    // },

    {
      path: "/liner/:area",
      name: "liner", // 邮轮
      component: () => import("@/views/Liner/liner.vue"),
      meta: {
        title: "",
      },
    },
    {
      path: "/visa",
      name: "visa", // 签证
      component: () => import("@/views/Visa/visa.vue"),
      meta: {
        title: "签证_环球行签证中心_签证代办_旅游签证_商务签证_探亲访友签证",
      },
    },
    {
      path: "/visa/list/:country",
      name: "visaList", // 签证列表
      component: () => import("@/views/Visa/list.vue"),
      meta: {
        title: "签证_环球行签证中心_签证代办_旅游签证_商务签证_探亲访友签证",
      },
    },
    {
      path: "/visa/details/:id",
      name: "visaDetails", // 签证详情
      component: () => import("@/views/Visa/details.vue"),
      meta: {
        title: "签证_环球行签证中心_签证代办_旅游签证_商务签证_探亲访友签证",
      },
    },
    {
      path: "/about",
      name: "about", // 关于
      component: () => import("@/views/About/about.vue"),
      meta: {
        title:
          "深圳环球行|深圳环球行旅行社|深圳旅游网|环球行|深圳环球行官方网站",
      },
    },
    {
      path: "/about/weixin",
      name: "weixin", // 客服微信
      component: () => import("@/views/About/weixin.vue"),
      meta: {
        title:
          "中国环球行_旅行社_欧洲旅游_出环球行游_公司旅游-中国环球行官方网站",
      },
    },
    {
      path: "/search",
      name: "lienSearch", // 旅游产品搜索页
      component: () => import("@/views/Search/search.vue"),
      meta: {
        title: "",
      },
    },
    {
      path: "/visa/search",
      name: "visaSearch", // 签证搜索页
      component: () => import("@/views/Search/visaSearch.vue"),
      meta: {
        title: "",
      },
    },
    {
      path: "/details/:id",
      name: "details", // 详情页
      component: () => import("@/views/details/details.vue"),
    },
    {
      path: "/area",
      name: "area", // 区域目的地
      component: () => import("@/views/Area/area.vue"),
    },
    {
      path: "/service/case",
      name: "case", // 服务案例
      component: () => import("@/views/servicepage/case.vue"),
    },
    {
      path: "/login",
      name: "login", // 登录
      component: () => import("@/views/user/login.vue"),
    },
    {
      path: "/myinfo/home",
      name: "myInfoHome", // 个人中心首页
      component: () => import("@/views/user/user.vue"),
    },
    {
      path: "/myinfo/information",
      name: "information", // 个人中心
      component: () => import("@/views/user/information.vue"),
    },
    {
      path: "/TemplateGeneration",
      name: "TemplateGeneration",
      component: () => import("@/views/TemplateStore/TemplateGeneration.vue"),
    },
    /* 
      我的订单
      我的收藏
      历史浏览
      我的消息
    */
    // {
    //   path: "/login",
    //   name: "login", // 登录
    //   component: () => import("@/views/user/login.vue"),
    // },
    // {
    //   path: "/login",
    //   name: "login", // 登录
    //   component: () => import("@/views/user/login.vue"),
    // },
  ],
});

// 全局级别路由前置守卫，对所有的跳转都有效
// to：即将要去的
// from: 现在在哪
router.beforeEach((to, from, next) => {
  //设置页面的标题
  let title = to.meta.title
    ? to.meta.title
    : "深圳环球行_旅行社_欧洲旅游_出环球行游_公司旅游-环球行官方网站";
  document.title = title;
  // return：
  // 1. 不return 相当于什么都没做，正常调整
  // 2. return false 不跳转，停留在当前也
  // 3. return 一个路由，跳转到这个路由（return '/home'）
  // 4. return 一个路由对象，跳转到路由name对应的地址 (return {name: home})

  // 检查即将进入的路由是否与当前路由相同
  if (to.name !== from.name) {
    // 如果不同，则滚动到顶部
    nextTick(() => {
      window.scrollTo(0, 0);
    });
  }

  // 判断百度归因, 绑定到url后面
  const bd_vid = sessionStorage.getItem("bd_vid");
  if (bd_vid && !to.query.bd_vid) {
    // 使用 `next` 函数进行跳转，并附加 `bd_vid` 参数
    next({ path: to.path, query: { ...to.query, bd_vid } });
  } else {
    next();
  }

  // 确保调用 next() 方法以继续路由导航
  // next();
});

export default router;
